package com.menu.system.service.impl;

import com.menu.common.utils.DateUtils;
import com.menu.system.domain.ReceptionRole;
import com.menu.system.mapper.receptionRoleMapper;
import com.menu.system.service.IreceptionRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 角色信息Service业务层处理
 *
 * @author ruoyi
 * @date 2024-06-06
 */
@Service
public class receptionRoleServiceImpl implements IreceptionRoleService {
    @Autowired
    private receptionRoleMapper receptionRoleMapper;

    /**
     * 查询角色信息
     *
     * @param roleId 角色信息主键
     * @return 角色信息
     */
    @Override
    public ReceptionRole selectreceptionRoleByRoleId(Long roleId) {
        return receptionRoleMapper.selectreceptionRoleByRoleId(roleId);
    }

    /**
     * 查询角色信息列表
     *
     * @param receptionRole 角色信息
     * @return 角色信息
     */
    @Override
    public List<ReceptionRole> selectreceptionRoleList(ReceptionRole receptionRole) {
        return receptionRoleMapper.selectreceptionRoleList(receptionRole);
    }

    /**
     * 新增角色信息
     *
     * @param receptionRole 角色信息
     * @return 结果
     */
    @Override
    @Transactional
    public int insertreceptionRole(ReceptionRole receptionRole) {
        receptionRole.setCreateTime(DateUtils.getNowDate());
        int i = receptionRoleMapper.insertreceptionRole(receptionRole);
        for (Long rold : receptionRole.getRolds()) {
            receptionRoleMapper.batchRoleMenu(receptionRole.getRoleId(),rold);
        }

        return i;
    }

    /**
     * 修改角色信息
     *
     * @param receptionRole 角色信息
     * @return 结果
     */
    @Override
    @Transactional
    public int updatereceptionRole(ReceptionRole receptionRole) {
        receptionRole.setUpdateTime(DateUtils.getNowDate());
        int i = receptionRoleMapper.updatereceptionRole(receptionRole);
        receptionRoleMapper.deleterbatchUserRoleIds(receptionRole.getRoleId());
        for (Long rold : receptionRole.getRolds()) {
                receptionRoleMapper.batchRoleMenu(receptionRole.getRoleId(),rold);
        }
        return i;
    }

    /**
     * 批量删除角色信息
     *
     * @param roleIds 需要删除的角色信息主键
     * @return 结果
     */
    @Override
    @Transactional
    public int deletereceptionRoleByRoleIds(Long[] roleIds) {
        return receptionRoleMapper.deletereceptionRoleByRoleIds(roleIds);
    }

    /**
     * 删除角色信息信息
     *
     * @param roleId 角色信息主键
     * @return 结果
     */
    @Override
    @Transactional
    public int deletereceptionRoleByRoleId(Long roleId) {
        return receptionRoleMapper.deletereceptionRoleByRoleId(roleId);
    }
}
